using System;
using Clandestine.Engines.Field;
using Qyoto;

namespace Shlick
{
	using Object = Clandestine.Engines.Field.Object;

	public class LayerTreeWidget : QWidget
	{
		public MapDocument MapDocument { get; private set; } 
		public Map Map { get { return this.MapDocument.Map; } } 
		public Object CurrentObject { get { return view.CurrentObject; } } // the object the current LayerTree is displying, if any.
		public LayerTreeMode Mode { get { return view.Mode; } }
		public LayerTreeItem SelectedItemType { get { return view.SelectedItemType; } }
		public event LayerTreeSelectionHandler ItemSelected 
		{ 
			add { view.ItemSelected += value; } 
			remove { view.ItemSelected -= value; }
		}
	
		// UI
		private LayerTreeView view;
		private QVBoxLayout vbox;
		private QPushButton objButton;
		
		public LayerTreeWidget(QWidget parent, MapDocument mapDocument, LayerTreeMode mode, bool haveContextMenu, Clandestine.Engines.Field.Object obj = null) : base(parent)
		{
			// Setup UI
			view = new LayerTreeView(this, mapDocument, mode, haveContextMenu, obj);
			objButton = new QPushButton("Stop Editing Object", this);
			vbox = new QVBoxLayout(this);
			vbox.AddWidget(objButton);
			vbox.AddWidget(view);
			
			UpdateMode(mode);
			
			Connect(objButton, SIGNAL("clicked()"), this, SLOT("buttonClicked()"));
		}
	
		public void UpdateMode(LayerTreeMode mode, Object o = null)
		{
			if (mode == LayerTreeMode.Object)
				objButton.SetVisible(true);
			else
				objButton.SetVisible(false);
				
			view.UpdateMode(mode, o);
		}
		
		[Q_SLOT("buttonClicked()")]
		private void buttonClicked()
		{
			this.UpdateMode(LayerTreeMode.Map);
		}
	}
}

